<?php session_start();  require_once('connections/con_gl.php'); ?>
<?php
//cekAkses($_SESSION[akses],"A-3");
$currentPage = $_SERVER["PHP_SELF"];

mysql_select_db($database_con_gl, $con_gl);
$query_l_kel = "SELECT kategori_id, kategori_nama FROM dcm_tm_kategori_dokumen ORDER BY kategori_nama ASC";
$l_kel = mysql_query($query_l_kel, $con_gl) or die(mysql_error());
$row_l_kel = mysql_fetch_assoc($l_kel);
$totalRows_l_kel = mysql_num_rows($l_kel);

mysql_select_db($database_con_gl, $con_gl);
$query_l_kel2 = "SELECT unitbisnis_id, unitbisnis_nama from dcm_tm_unitbisnis";
$l_kel2 = mysql_query($query_l_kel2, $con_gl) or die(mysql_error());
$row_l_kel2 = mysql_fetch_assoc($l_kel2);
$totalRows_l_kel2 = mysql_num_rows($l_kel2);

mysql_select_db($database_con_gl, $con_gl);
if($_GET['cr_kel']!=""){
$query_l_kel1 = "SELECT status_id, status_nama FROM dcm_ref_status_dokumen ORDER BY status_nama ASC";
}else{
$query_l_kel1 = "SELECT status_id, status_nama FROM dcm_ref_status_dokumen ORDER BY status_nama ASC";
}
$l_kel1 = mysql_query($query_l_kel1, $con_gl) or die(mysql_error());
$row_l_kel1 = mysql_fetch_assoc($l_kel1);
$totalRows_l_kel1 = mysql_num_rows($l_kel1);

$maxRows_data = 10;
$pageNum_data = 0;
if (isset($_GET['pageNum_data'])) {
  $pageNum_data = $_GET['pageNum_data'];
}
$startRow_data = $pageNum_data * $maxRows_data;
$cr_txt = str_replace("+"," ",$_REQUEST[cr_txt]);
mysql_select_db($database_con_gl, $con_gl);

$query_data = "SELECT * from v_document where status_id = '12'";
if($_SESSION['unitbisnis_id'] !='1')
{
	
	$query_data .=" AND unitbisnis_id = '$_SESSION[unitbisnis_id]'";
}
else
{
	//echo $_SESSION['unitbisnis_id'];

}

//print_r($query_data);
if(isset($_GET[cr_txt]) AND $_GET[cr_txt]<>'' AND $_GET[cr_txt]<>'+') { 
$decode_cr = str_replace("+"," ",$_GET[cr_txt]);
$query_data .="AND NODOCUMENT LIKE '%%$decode_cr%%' OR NAMADOCUMENT LIKE '%%$decode_cr%%'";
}
//cr_kel
if(isset($_GET[cr_kel]) AND $_GET[cr_kel]<>'ALL') { 
$query_data .="AND kategori_id ='$_GET[cr_kel]'";
}
if(isset($_GET[cr_kel1]) AND $_GET[cr_kel1]<>'ALL') { 
$query_data .=" AND status_id ='$_GET[cr_kel1]'";
}
$query_data .=" ORDER BY NAMADOCUMENT, NODOCUMENT ASC";

$data = mysql_query($query_data, $con_gl) or die(mysql_error());
$totalRows_data = mysql_num_rows($data);

$totalPages_data = floor($totalRows_data / $maxRows_data);

$query_data .=" LIMIT $startRow_data, $maxRows_data";
$data = mysql_query($query_data, $con_gl) or die(mysql_error());
$totalRow_data = mysql_num_rows($data);
$row_data = mysql_fetch_assoc($data);

$queryString_data = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_data") == false && 
        stristr($param, "totalRows_data") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_data = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_data = sprintf("&totalRows_data=%d%s", $totalRows_data, $queryString_data);
include('../queryUNITBISNIS/include/widget_exportdata.php');
//$actual_link = "http://$_SERVER[HTTP_HOST]/research/index.php?";
//echo $actual_link;
?>
<h1>DISTRIBUSI DOCUMENT </h1>
<h2><?php echo $_SESSION['unitbisnis_nama'];?></h2>
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable"> 
  <tr valign="top" bgcolor="#FFFFFF" class="hide">
        <td><?php if(strstr($_SESSION[akses],"A-1") or strstr($_SESSION[akses],"A-4-1")) { ?><?php } ?></td>
        <td colspan="8" align="left" style="border-bottom:solid 1px #E2EAC1;border-right:solid 1px #E2EAC1;"><form id="search" name="search" method="post" action="">
          <label><strong>KATEOGRI  :   
            </strong>
            <select name="cr_kel" id="cr_kel" style="width:180px;" onchange="javascript: window.location.href='index.php?component=distribusi&amp;cr_kel='+this.value;"> <!-- INI BUAT RETRIVE JIKA DI CLICK -->
          <option value="ALL" <?php if (!(strcmp("ALL", $_GET[cr_kel]))) {echo "selected=\"selected\"";} ?>>PILIH KATEGORI</option>
          <?php
do {  
?>
          <option value="<?php echo $row_l_kel['kategori_id']?>"<?php if (!(strcmp($row_l_kel['kategori_nama'], $_GET[cr_kel]))) {echo "selected=\"selected\"";} ?>><?php echo $row_l_kel['kategori_nama']; ?></option>
          <?php
} while ($row_l_kel = mysql_fetch_assoc($l_kel));
  $rows = mysql_num_rows($l_kel);
  if($rows > 0) {
      mysql_data_seek($l_kel, 0);
	  $row_l_kel = mysql_fetch_assoc($l_kel);
  }
?>
        </select>
  </label>
      <label>
  <!-- Edit by suwondo -->
  <input name="cr_txt" type="text" id="cr_txt" placeholder="Find by: No Document, Nama Document"; onclick="this.value='';"<?php echo $_REQUEST['cr_txt'];?>" size="25" maxlength="100" />
</label>
      <label>
      <input name="Search" type="submit" id="Search" value="Search" />
      </label>
    </form>
	<?php
	if(isset($_POST['Search'])) {
		echo "<script>window.location=\"index.php?component=distribusi&cr_kel=".$_POST[cr_kel]."&cr_txt=".str_replace(" ","+",$_POST[cr_txt])."\";</script>";
	}
	?></td>
  </tr>
  <tr>
    <th width="159"><strong>TLG UPLOAD</strong></th>
    <th width="100"><strong>KATEGORI</strong></th>
    <th width="100"><strong>STATUS</strong></th>
    <th width="250">NO DOCUMENT </th>
    <th width="250" colspan="2">NAMA DOCUMENT</th>
    <th width="90">DIPERIKSA</th>
    <th width="130">DISETUJUI </th>
  </tr>
  <?php if($totalRows_data > 0) { ?>
  <?php do { ?>
    <tr valign="top" bgcolor="#FFFFFF">
      <td><?php echo $row_data['TGLUPLOAD']; ?></td>
      <td><?php echo $row_data['KATEGORI']; ?></td>
      <td><?php echo $row_data['STATUS']; ?></td>
      <td><?php echo $row_data['NODOCUMENT']; ?></td>
      <td><?php echo $row_data['NAMADOCUMENT']; ?></td>
      <td><a href="download.php?filename=<?php echo $row_data['path_url'];?>" title="Download Arsip"><img src="images/download.png" alt="" width="16" border="0" align="right" /></a></td>
      <td><?php echo $row_data['DIPERIKSA']; ?></td>
      <td><?php echo $row_data['DISETUJUI']; ?></td>
      </tr>
    <?php } while ($row_data = mysql_fetch_assoc($data)); ?>
	<?php if($totalRows_data > $maxRows_data) { ?>
    <tr class="hide">
      <td colspan="10"><table border="0" align="left" width="50%">
          <tr>
            <td width="3%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, 0, $queryString_data); ?>"><img src="../pengajuanrevisi/First.gif" border=0 ></a>
            <?php } // Show if not first page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, max(0, $pageNum_data - 1), $queryString_data); ?>"><img src="../pengajuanrevisi/Previous.gif" border=0></a>
            <?php } // Show if not first page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, min($totalPages_data, $pageNum_data + 1), $queryString_data); ?>"><img src="../pengajuanrevisi/Next.gif" border=0></a>
            <?php } // Show if not last page ?>            </td>
            <td width="3%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
                <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, $totalPages_data, $queryString_data); ?>"><img src="../pengajuanrevisi/Last.gif" border=0></a>
            <?php } // Show if not last page ?>            </td>
			<td width="88%">Halaman : <?php echo $pageNum_data+1; ?>, Ditampilkan <?php echo $totalRow_data; ?> dari <?php echo $totalRows_data; ?> total data</td>
          </tr>
        </table></td>
    </tr>
	<?php } ?>
   <?php }else{ ?>
  <tr bgcolor="#FFFFFF">
    <td colspan="9">Data tidak ada !!! </td>
  </tr>
  <?php } ?>
  <tr class="hide">
    <td colspan="9"><?php if(strstr($_SESSION[akses],"DD-8-1")) { ?><a href="../document - Copy/include/add_document.php"><img src="../document - Copy/images/add_new.png" border="0" /></a><?php } ?></td>
  </tr>
</table>


<?php
mysql_free_result($data);

mysql_free_result($l_kel);
?>
